#!/bin/bash

# Conversione dei csv forniti da Bcc in csv importabili da Homebank
echo "DATE;PAYMODE;INFO;PAYEE;MEMO;AMOUNT;CATEGORY;TAGS" > out_$1
awk 'BEGIN {ORS="";  FS=";" }
$1~/[0-9]/ {
  print $3 ";";  #date
  print    ";";  #paymode
  print    ";";  #info
  print    ";";  #payee
  print $5 ";";  #memo
  print $6 ";";  #amount
  print      ";" #category
  print      ""  #tags
  print "\n"
  if ($9) {
    print $3 ";";         #date
    print    ";";         #paymode
    print    ";";         #info
    print    ";";         #payee
    print "Commissioni;"; #memo
    print $9 ";";         #amount
    print    ";"          #category
    print    ""           #tags
    print "\n"
  }
}
END {
}
'  $1 |
iconv -f cp1251 -t utf-8 >> out_$1
